*------------------------------------------------------------------------------*
* 	Table 1: Gender Diff. in Loan Approval: Non-experimental - OLS		 	   *
*------------------------------------------------------------------------------*
{
cd "$data"
use ObservationalData_Applications, clear

**********************Panel A: All Loan Requests -- All Applicants (columns 1,2,3)
*Unadjusted Mean Diff.
regress approved fem, r
sum approved if fem==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_123.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br 
local append "append"            
*Model (1)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m, r
sum approved if fem==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_123.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br 
local append "append"            
*Model (2)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 age_25_35 age_36_45 age_46_55 age_56_65 age_66_or_more wage_range_0_600 wage_range_600_1200 married, r
sum approved if fem==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_123.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"         


**********************Panel A: All Loan Requests -- Only Non-Client Applicants (columns 5,6,7)
*Unadjusted Mean Diff.
regress approved fem if bank_client==0, r
sum approved if fem==0 & bank_client==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_567.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br 
local append "append"            
*Model (1)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m if bank_client==0, r
sum approved if fem==0 & bank_client==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_567.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br 
local append "append"            
*Model (2)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 age_25_35 age_36_45 age_46_55 age_56_65 age_66_or_more wage_range_0_600 wage_range_600_1200 married if bank_client==0, r
sum approved if fem==0 & bank_client==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_567.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br 
local append "append"            

**********************Panel B: Only $1,500 - $13,500 USD Loan Requests among Applicants Aged 25-35 --- All Applicants (columns 1,2,3)

*Unadjusted Mean Diff.
regress approved fem if ammount>=1000000 & ammount<=9000000 & age_25_35==1, r
sum approved if fem==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_123.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"            
*Model (1)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m  if ammount>=1000000 & ammount<=9000000 & age_25_35==1, r
sum approved if fem==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_123.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br 
local append "append"            
*Model (2)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 wage_range_0_600 wage_range_600_1200 married  if ammount>=1000000 & ammount<=9000000 & age_25_35==1, r
sum approved if fem==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_123.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br 
local append "append"            

**********************Panel B: Only $1,500 - $13,500 USD Loan Requests among Applicants Aged 25-35 --- Only Non-Client Applicants  (columns 5,6,7)

*Unadjusted Mean Diff.
regress approved fem if bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1, r
sum approved if fem==0 & bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_567.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"            
*Model (1)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m if bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1, r
sum approved if fem==0 & bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_567.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"            
*Model (2)
xi: regress approved fem dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 wage_range_0_600 wage_range_600_1200 married if bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1, r
sum approved if fem==0 & bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_567.xls", keep(fem) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"  




*Matching ATE

*Panel A - Column 4

/*We select the random sample of 15,000 observations to run the matching estimator
cd "$data"
use ObservationalData_Applications, clear
sort fem married age_25_35 approved ins_cod date_m ammount 
set seed 1010101010
bsample 15000 
sort fem married age_25_35 approved ins_cod date_m ammount 
save "C:\Users\Raimundo Undurraga\Dropbox\JPE Micro Gender\JPE Micro Submission\Submission Post Acceptance\Replication\Data\ObservationalData_Applications_randomsample15000_A4.dta", replace
*/

cd "$data"
use ObservationalData_Applications_randomsample15000_A4, clear

xi:  teffects nnmatch (approved dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 age_25_35 age_36_45 age_46_55 age_56_65 age_66_or_more wage_range_0_600 wage_range_600_1200 married) (fem), vce(robust)
sum approved if fem==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_4.xls", keep(ate) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"            

*Panel A - Column 8

/*We select the random sample of 15,000 observations to run the matching estimator
cd "$data"
use ObservationalData_Applications, clear
sort fem married age_25_35 approved ins_cod date_m ammount 
set seed 1010101010
bsample 15000 if bank_client==0
sort fem married age_25_35 approved ins_cod date_m ammount 
save "C:\Users\Raimundo Undurraga\Dropbox\JPE Micro Gender\JPE Micro Submission\Submission Post Acceptance\Replication\Data\ObservationalData_Applications_randomsample15000_A8.dta", replace
*/

cd "$data"
use ObservationalData_Applications_randomsample15000_A8, clear

xi:  teffects nnmatch (approved dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 age_25_35 age_36_45 age_46_55 age_56_65 age_66_or_more wage_range_0_600 wage_range_600_1200 married) (fem), vce(robust)
sum approved if fem==0 & bank_client==0
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelA_8.xls", keep(ate) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"            

*Panel B - Column 4

/*We select the random sample of 15,000 observations to run the matching estimator
cd "$data"
use ObservationalData_Applications, clear
sort fem married age_25_35 approved ins_cod date_m ammount 
set seed 1010101010
bsample 15000 if ammount>=1000000 & ammount<=9000000 & age_25_35==1
sort fem married age_25_35 approved ins_cod date_m ammount 
save "C:\Users\Raimundo Undurraga\Dropbox\JPE Micro Gender\JPE Micro Submission\Submission Post Acceptance\Replication\Data\ObservationalData_Applications_randomsample15000_B4.dta", replace
*/

cd "$data"
use ObservationalData_Applications_randomsample15000_B4, clear

xi:  teffects nnmatch (approved dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 wage_range_0_600 wage_range_600_1200 married) (fem), vce(robust)
sum approved if fem==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_4.xls", keep(ate) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"            


*Panel B - Column 8

/*We select the random sample of 15,000 observations to run the matching estimator
cd "$data"
use ObservationalData_Applications, clear
sort fem married age_25_35 approved ins_cod date_m ammount 
set seed 1010101010
bsample 15000 if bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
sort fem married age_25_35 approved ins_cod date_m ammount 
save "C:\Users\Raimundo Undurraga\Dropbox\JPE Micro Gender\JPE Micro Submission\Submission Post Acceptance\Replication\Data\ObservationalData_Applications_randomsample15000_B8.dta", replace
*/

cd "$data"
use ObservationalData_Applications_randomsample15000_B8, clear

xi:  teffects nnmatch (approved dummy_ammount_2*##i.dummy_lenght_* i.ins_cod i.date_m debt_sys debt_sys_d1-debt_sys_d9 debt_bank_d1-debt_bank_d9 score_d1-score_d9 wage_range_0_600 wage_range_600_1200 married) (fem), vce(robust)
sum approved if fem==0 & bank_client==0 & ammount>=1000000 & ammount<=9000000 & age_25_35==1
local mean_male = r(mean)
outreg2 fem using "${tables}/Table1_PanelB_8.xls", keep(ate) addstat("mean_male", `mean_male') adec(4) bdec(4) sdec(4) excel `append' stats(coef se) auto(4) alpha(.01, .05, .10) symbol(***,**,*) br
local append "append"            

}
